layui.use(['layer', 'form', 'jquery', 'table', 'laydate'], function () {
    var layer = layui.layer;
    var form = layui.form;
    var $ = layui.jquery;
    var table = layui.table;
    var laydate = layui.laydate;
    laydate.render({
        elem: '#createDate',
        type: 'date',
        trigger: 'click'
    });
    //加载表格数据
    getTable();

    function getTable() {
        $.ajax({
            url: '/jsLog/getLog',
            type: 'post',
            dataType: 'json',
            data: {'logType': 3},
            success: function (data) {
                tablereload(data.data);
            }
        });
    }

    //表格加载
    function tablereload(data) {
        table.render({
            elem: '#table',
            id: 'table',
            data: data,
            title: '微圈操作日志',
            toolbar: '#toolbar',
            page: {
                limit: 10,
                layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
                first: '首页',
                last: '尾页'
            },
            cols: [
                [
                    {type: 'checkbox'},
                    {
                        field: '', title: '序号', align: 'center', templet: function (data) {
                            return data.LAY_INDEX;
                        }
                    },
                    {
                        field: 'type', title: '操作类型', align: 'center', templet: function (data) {
                            if (data.type == 3) {
                                return '删除';
                            }
                            if (data.type == 5) {
                                return '查找';
                            } else {
                                return '无操作';
                            }
                        }
                    },
                    {field: 'trueName', title: '执行人员', align: 'center'},
                    {field: 'createDate', title: '执行时间', align: 'center'},
                    {field: 'remark', title: '操作备注', align: 'center'},
                    {
                        field: '', title: '操作', align: 'center', templet: function (data) {
                            return "<div><a href='javascript:deleteLog(\"" + data.logId + "\")' style='color: #2F4056;margin-left: 10px'>删除</a></div>"
                        }
                    },
                ]
            ]
        });
    }

    //删除微圈操作日志
    deleteLog = function deleteLog(id) {
        layer.confirm('是否删除此微圈操作记录', {
            icon: 3, title: '提示'
        }, function (index) {
            $.ajax({
                url: '/jsLog/deleteLog',
                type: 'post',
                dataType: 'json',
                data: {'logId': id},
                success: function (data) {
                    if (data.data) {
                        layer.msg("删除成功");
                        location.reload();
                    } else {
                        layer.msg("删除失败")
                    }
                }
            });
        })
    }
    //搜索
    form.on('submit(search)', function (data) {
        $.ajax({
            url: '/jsLog/getLog?logType=3',
            type: 'post',
            dataType: 'json',
            data: data.field,
            success: function (data) {
                tablereload(data.data);
            }
        });
    })
    //重置
    $('#reset').click(function () {
        $('input[name=trueName]').val('');
        $('input[name=createDate]').val('');
        getTable();
    });
    //返回
    goBack = function goBack(){
        //跳转课程列表
        parent.$('#Jump').val('微圈列表');
        parent.getQuick();
        return;
    }
});